from otherparty.common import run_hg
from dirstate.utils import updateSvnRepo,IS_HSVG_REPO
from os.path import join
import os

def writeInFile(str,file):
	f = open(file,'w')
	f.write(str)
	f.close()

DEFAULT_HGIGNORE = r"""\.svn.*/
?\.orig
^lib/
^classes/
^utils/
^trunkData2
?\.mine
?\.r[0-9]+
?\.log
?\.conflict
"""

DEFAULT_INCLUDE = """src
data2
PLSQL
devLibs
"""

DEFAULT_HGRC = r"""[extensions]
hgext.mq = 
"""
def doInit():
	"""Inicializa un repositorio svn a hsvg"""
	if not IS_HSVG_REPO:
		print 'inicializando repo...'
		run_hg(['init'])
		writeInFile(DEFAULT_HGIGNORE,'.hgignore')
		writeInFile(DEFAULT_HGRC,join('.hg','hgrc'))
		os.mkdir(join('.hg','hsvg'))
		writeInFile(DEFAULT_INCLUDE,join('.hg','hsvg','include.txt'))
		run_hg(['ci','-Am','inicial'])	
		updateSvnRepo()
		print '...terminado!'
	else:
		print 'Este ya es un repositorio hsvg.'
	
def main():
	doInit()

if __name__ == '__main__':
	main()